home *** CD-ROM | disk | FTP | other *** search
/ Just Call Me Internet / Just Call Me Internet.iso / prog / atari / c / nos042_s / ppppap.c < prev    next >
C/C++ Source or Header  |  1994-09-16  |  17KB  |  734 lines

  1. /*
  2.  *  PPPPAP.C    -- Password Authentication Protocol for PPP
  3.  *
  4.  *    This implementation of PPP is declared to be in the public domain.
  5.  *
  6.  *    Jan 91    Bill_Simpson@um.cc.umich.edu
  7.  *        Computer Systems Consulting Services
  8.  *
  9.  *    Acknowledgements and correction history may be found in PPP.C
  10.  *
  11.  * ATARI Version by David Nash - dnash@chaos.demon.co.uk
  12.  */
  13.  
  14. /****************************************************************************
  15. *    $Id: ppppap.c 1.2 93/07/16 11:49:26 ROOT_DOS Exp $
  16. *    14 Jul 93    1.2        GT    Fix warnings.                                    *
  17. ****************************************************************************/
  18.  
  19. #include <stdio.h>
  20. #include "global.h"
  21. #include "mbuf.h"
  22. #include "proc.h"
  23. #include "iface.h"
  24. #include "session.h"
  25. #include "socket.h"
  26. #include "ppp.h"
  27. #include "pppfsm.h"
  28. #include "ppplcp.h"
  29. #include "ppppap.h"
  30. #include "cmdparse.h"
  31. #include "files.h"
  32. #include "trace.h"
  33. #include "main.h"
  34. #include "ip.h"
  35.  
  36. static int dopap_user        __ARGS((int argc, char *argv[], void *p));
  37.  
  38. static void __stdargs pap_monitor __ARGS((int mustask, void *v1, void *v2));
  39. static void pap_pwdlookup __ARGS((struct pap_s *pap_p));
  40.  
  41. static struct mbuf *pap_makereq __ARGS((struct fsm_s *fsm_p));
  42.  
  43. static int pap_verify __ARGS((char *username, char *password));
  44. static void pap_shutdown __ARGS((struct fsm_s *fsm_p));
  45. static void pap_opening __ARGS((struct fsm_s *fsm_p, int flag));
  46.  
  47. static int pap_request    __ARGS((struct fsm_s *fsm_p,
  48.             struct config_hdr *hdr,
  49.             struct mbuf *data));
  50. static int pap_check    __ARGS((struct fsm_s *fsm_p,
  51.             struct config_hdr *hdr,
  52.             struct mbuf *data));
  53. static void pap_timeout    __ARGS((void *vp));
  54.  
  55. static void pap_free    __ARGS((struct fsm_s *fsm_p));
  56.  
  57.  
  58. static struct fsm_constant_s pap_constants = {
  59.     "Pap",
  60.     PPP_PAP_PROTOCOL,
  61.     0x000E,                /* codes 1-3 recognized */
  62.  
  63.     Pap,
  64.     PAP_REQ_TRY,
  65.     PAP_FAIL_MAX,
  66.     0,
  67.     PAP_TIMEOUT * 1000L,
  68.  
  69.     pap_free,
  70.  
  71.     fsm_no_action,        /* pap_reset, */
  72.     fsm_no_action,        /* pap_starting, */
  73.     fsm_no_action,        /* pap_opening, */
  74.     fsm_no_action,        /* pap_closing, */
  75.     fsm_no_action,        /* pap_stopping, */
  76.  
  77.     pap_makereq,
  78.     fsm_no_check,        /* pap_request, */
  79.     fsm_no_check,        /* pap_ack, */
  80.     fsm_no_check,        /* pap_nak, */
  81.     fsm_no_check,        /* pap_reject */
  82. };
  83.  
  84.  
  85. /****************************************************************************/
  86.  
  87. /* "ppp <iface> pap" subcommands */
  88. static struct cmds Papcmds[] = {
  89.     { "timeout",    doppp_timeout,    0,    0,    NULLCHAR },
  90.     { "try",        doppp_try,    0,    0,    NULLCHAR },
  91.     { "user",        dopap_user,    0,    0,    NULLCHAR },
  92.     { NULLCHAR },
  93. };
  94.  
  95.  
  96. int
  97. doppp_pap(argc,argv,p)
  98. int argc;
  99. char *argv[];
  100. void *p;
  101. {
  102.     register struct iface *ifp = p;
  103.     register struct ppp_s *ppp_p = ifp->edv;
  104.  
  105.     return subcmd(Papcmds, argc, argv, &(ppp_p->fsm[Pap]));
  106. }
  107.  
  108.  
  109. /* Set user/password */
  110. int
  111. dopap_user(argc,argv,p)
  112. int argc;
  113. char *argv[];
  114. void *p;
  115. {
  116.     register struct fsm_s *fsm_p = p;
  117.     register struct pap_s *pap_p = fsm_p->pdv;
  118.  
  119.     if (argc < 2) {
  120.         tprintf("%s\n",
  121.             (pap_p->username == NULLCHAR) ? "None" : pap_p->username);
  122.         return 0;
  123.     }
  124.     free(pap_p->username);
  125.     pap_p->username = NULLCHAR;
  126.     free(pap_p->password);
  127.     pap_p->password = NULLCHAR;
  128.  
  129.     if (stricmp(argv[1],"none") != 0) {
  130.         pap_p->username = strdup(argv[1]);
  131.         if (argc > 2) {
  132.             pap_p->password = strdup(argv[2]);
  133.         } else {
  134.             pap_pwdlookup( pap_p );
  135.         }
  136.     }
  137.     return 0;
  138. }
  139.  
  140.  
  141. /****************************************************************************/
  142. /* Bring up a session on the console for for the username/password.
  143.  * Return a NULLCHAR in either username or password if aborted.
  144.  */
  145. static void
  146. __stdargs pap_monitor(unused, v1, v2)
  147. int unused;
  148. void *v1;
  149. void *v2;
  150. {
  151.     struct iface *iface = v1;
  152.     struct fsm_s *fsm_p = v2;
  153.     struct pap_s *pap_p = fsm_p->pdv;
  154.     char buf[21];
  155.     struct session *sp;
  156.     int wait_code = 0;
  157.  
  158.     /* Allocate a session control block */
  159.     if((sp = newsession("PPP/PAP",PPPPASS)) == NULLSESSION){
  160.         tprintf("Too many sessions\n");
  161.         return;
  162.     }
  163.  
  164.     while ( !main_exit && wait_code == 0 ) {
  165.         /* get user name */
  166.         if (pap_p->username == NULLCHAR) {
  167.             tprintf ("%s: PPP/PAP  Username: ", iface->name);
  168.             usflush(sp->output);
  169.             if (recvline(sp->input,buf,20) > 0) {
  170.                 rip(buf);
  171.                 if (strlen(buf) > 0) {
  172.                     pap_p->username = strdup(buf);
  173.                 }
  174.             }
  175.         } else {
  176.             tprintf ("%s: PPP/PAP  Username: %s\n",
  177.                 iface->name, pap_p->username);
  178.             usflush(sp->output);
  179.         }
  180.  
  181.         /* get pass word */
  182.         if (pap_p->username != NULLCHAR
  183.          && pap_p->password == NULLCHAR) {
  184.             /* turn off echo */
  185.             sp->ttystate.echo = 0;
  186.             tprintf("%s: PPP/PAP  Password: ",iface->name);
  187.             usflush(sp->output);
  188.             if (recvline(sp->input,buf,20) > 0) {
  189.                 rip(buf);
  190.                 if ( strlen(buf) > 0 ) {
  191.                     pap_p->password = strdup(buf);
  192.                 }
  193.             }
  194.             tprintf("\n");
  195.             usflush(sp->output);
  196.             /* Turn echo back on */
  197.             sp->ttystate.echo = 1;
  198.         }
  199.  
  200.         /* send pap request */
  201.         fsm_sendreq(fsm_p);
  202.         wait_code = pwait ( pap_p );
  203.  
  204.         /* show ack/nak reply */
  205.         if ( wait_code != EABORT && pap_p->message != NULLCHAR ) {
  206.             tprintf ("%s: PPP/PAP  %s\n",
  207.                 iface->name, pap_p->message );
  208.         }
  209.         tprintf ( "\n" );
  210.         usflush(sp->output);
  211.  
  212.     }
  213.  
  214.     /* clean up */
  215.     if ( wait_code != EABORT ) {
  216.         Pause ( 10000L );
  217.     }
  218.     freesession(sp);
  219.     pap_p->pp = NULLPROC;
  220. }
  221.  
  222.  
  223. /* Check the FTP userfile for this user; get password if available */
  224. static void
  225. pap_pwdlookup(pap_p)
  226. struct pap_s *pap_p;
  227. {
  228.     char *buf;
  229.     char *password;
  230.     int permission;
  231.  
  232.     if ( pap_p->username == NULLCHAR )
  233.         return;
  234.  
  235.     if ( (buf = userlookup( pap_p->username, &password, NULLCHARP,
  236.             &permission, NULL )) == NULLCHAR )
  237.         return;
  238.  
  239.     /* Check permissions for this user */
  240.     if ( (permission & PPP_PWD_LOOKUP) == 0 ) {
  241.         /* Not in ftpuser file for password lookup */
  242.         free(buf);
  243.         return;
  244.     }
  245.  
  246.     /* Save the password from this userfile record */
  247.     if ( strlen(password) != 0 )
  248.         pap_p->password = strdup(password);
  249.     free(buf);
  250. }
  251.  
  252.  
  253. /*******************************************/
  254. /* Verify user and password sent by remote host */
  255. static int
  256. pap_verify(username,password)
  257. char *username;
  258. char *password;
  259. {
  260.     int privs;
  261.     char *path;
  262.     int anony = 0;
  263.  
  264.     /* Use same login as FTP server */
  265.     path = mallocw(128);
  266.     privs = userlogin(username,password,&path,128,&anony);
  267.     free(path);
  268.  
  269.     /* Check privs for this user */
  270.     if (privs == -1) {
  271.         trace_log(PPPiface,"PAP: username/password incorrect or not found: %s",
  272.                 username);
  273.         return -1;
  274.     }
  275.  
  276.     if ((privs & PPP_ACCESS_PRIV) == 0) {
  277.         trace_log(PPPiface,"PAP: no permission for PPP access: %s",
  278.                 username);
  279.         return -1;
  280.     }
  281.     return 0;
  282. }
  283.  
  284.  
  285. /****************************************************************************/
  286. /* Build a request to send to remote host */
  287. static struct mbuf *
  288. pap_makereq(fsm_p)
  289. struct fsm_s *fsm_p;
  290. {
  291.     struct pap_s *pap_p = fsm_p->pdv;
  292.     struct mbuf *req_bp = NULLBUF;
  293.     register char *cp;
  294.     int len;
  295.  
  296.     PPP_DEBUG_ROUTINES("pap_makereq()");
  297.  
  298.     if ( pap_p->username == NULLCHAR
  299.      ||  pap_p->password == NULLCHAR ) {
  300.         fsm_log( fsm_p, "NULL username or password" );
  301.         return NULLBUF;
  302.     }
  303.  
  304. #ifdef PPP_DEBUG_OPTIONS
  305.     if (PPPtrace & PPP_DEBUG_OPTIONS)
  306.         trace_log(PPPiface, "    making user id %s", pap_p->username);
  307. #endif
  308.  
  309.     /* Get buffer for authenticate request packet */
  310.     len = 2 + strlen(pap_p->username) + strlen(pap_p->password);
  311.     if ((req_bp = alloc_mbuf(len)) == NULLBUF)
  312.         return NULLBUF;
  313.  
  314.     /* Load user id and password for authenticate packet */
  315.     cp = req_bp->data;
  316.     *cp++ = (char)strlen(pap_p->username);
  317.     if ( strlen(pap_p->username) > 0 )
  318.         cp = stpcpy(cp, pap_p->username);
  319.  
  320.     *cp++ = (char)strlen(pap_p->password);
  321.     if ( strlen(pap_p->password) > 0 )
  322.         cp = stpcpy(cp, pap_p->password);
  323.  
  324.     req_bp->cnt += len;
  325.     return(req_bp);
  326. }
  327.  
  328.  
  329. /****************************************************************************/
  330.  
  331. /* abandon PAP attempt; shutdown LCP layer */
  332. static void
  333. pap_shutdown(fsm_p)
  334. struct fsm_s *fsm_p;
  335. {
  336.     struct ppp_s *ppp_p = fsm_p->ppp_p;
  337.  
  338.     PPP_DEBUG_ROUTINES("pap_shutdown()");
  339.  
  340.     if (PPPtrace > 1)
  341.         fsm_log( fsm_p, "Failed; close connection" );
  342.  
  343.     fsm_close( &(ppp_p->fsm[Lcp]) );
  344. }
  345.  
  346.  
  347. /* Configuration negotiation complete */
  348. static void
  349. pap_opening(fsm_p, flag)
  350. struct fsm_s *fsm_p;
  351. int flag;
  352. {
  353.     register struct ppp_s *ppp_p = fsm_p->ppp_p;
  354.  
  355.     fsm_log(fsm_p, "Open");
  356.  
  357.     stop_timer(&(fsm_p->timer));
  358.  
  359.     if ( !((fsm_p->flags &= ~flag) & (PPP_AP_LOCAL | PPP_AP_REMOTE)) ) {
  360.         fsm_p->state = fsmOPENED;
  361.     }
  362.     ppp_p->flags &= ~flag;
  363.     ppp_ready(ppp_p);
  364. }
  365.  
  366.  
  367. /****************************************************************************/
  368. /* Check request from remote host */
  369. static int
  370. pap_request(fsm_p, hdr, data)
  371. struct fsm_s *fsm_p;
  372. struct config_hdr *hdr;
  373. struct mbuf *data;
  374. {
  375.     struct mbuf *reply_bp;
  376.     int result;
  377.     char *message;
  378.     int mess_length;
  379.     char *username = NULLCHAR;
  380.     int userlen;
  381.     char *password = NULLCHAR;
  382.     int passwordlen;
  383.  
  384.     PPP_DEBUG_ROUTINES("pap_request()");
  385.  
  386.     /* Extract userID/password sent by remote host */
  387.     if ( (userlen = pullchar(&data)) != -1 ) {
  388.         register int i;
  389.         register char *cp;
  390.  
  391.         cp = username = mallocw(userlen+1);
  392.         for ( i = userlen; i-- > 0; ) {
  393.             *cp++ = PULLCHAR(&data);
  394.         }
  395.         *cp = '\0';
  396.     }
  397.  
  398. #ifdef PPP_DEBUG_OPTIONS
  399.     if (PPPtrace & PPP_DEBUG_OPTIONS)
  400.         trace_log(PPPiface,"    checking user: %s", username);
  401. #endif
  402.  
  403.     if ( (passwordlen = pullchar(&data)) != -1 ) {
  404.         register int i;
  405.         register char *cp;
  406.  
  407.         cp = password = mallocw(passwordlen+1);
  408.         for ( i = passwordlen; i-- > 0; ) {
  409.             *cp++ = PULLCHAR(&data);
  410.         }
  411.         *cp = '\0';
  412.     }
  413.  
  414. #ifdef PPP_DEBUG_OPTIONS
  415.     if (PPPtrace & PPP_DEBUG_OPTIONS)
  416.         trace_log(PPPiface,"    checking password: %s", password);
  417. #endif
  418.  
  419.     if (pap_verify(username,password) == 0) {
  420.         free( fsm_p->ppp_p->peername );
  421.         fsm_p->ppp_p->peername = strdup(username);
  422.         result = CONFIG_ACK;
  423.         message = " Welcome";
  424.     } else {
  425.         result = CONFIG_NAK;
  426.         message = " Invalid username or password";
  427.     }
  428.  
  429.     /* the space at the beginning of the message is crucial */
  430.     /* it is replaced with the length of the message */
  431.     mess_length = strlen(message);
  432.     reply_bp = qdata(message,mess_length);
  433.     reply_bp->data[0] = (char)(mess_length - 1);
  434.  
  435.     fsm_send(fsm_p, result, hdr->id, reply_bp);
  436.  
  437.     if (result == CONFIG_NAK) {
  438.         if ( fsm_p->retry_nak > 0 ) {
  439.             fsm_p->retry_nak--;
  440.         } else {
  441.             pap_shutdown(fsm_p);
  442.         }
  443.     }
  444.     free_p(data);
  445.     free(username);
  446.     free(password);
  447.     return (result != CONFIG_ACK);
  448. }
  449.  
  450.  
  451. /* Check acknowledgement from remote host */
  452. static int
  453. pap_check(fsm_p, hdr, data)
  454. struct fsm_s *fsm_p;
  455. struct config_hdr *hdr;
  456. struct mbuf *data;
  457. {
  458.     struct pap_s *pap_p = fsm_p->pdv;
  459.     char *message;
  460.     int mess_length;
  461.     int full_length;
  462.     int len;
  463.  
  464.     PPP_DEBUG_ROUTINES("pap_check()");
  465.  
  466.     /* ID field must match last request we sent */
  467.     if (hdr->id != fsm_p->lastid) {
  468.         PPP_DEBUG_CHECKS("PAP: wrong ID");
  469.         tprintf ("id mismatch hdrid=%d, lastid=%d\n",
  470.             hdr->id, fsm_p->lastid);
  471.         free_p(data);
  472.         return -1;
  473.     }
  474.  
  475.     /* Log ASCII message from remote host, if any */
  476.     if ( (mess_length = pullchar(&data)) != -1 ) {
  477.         message = mallocw( mess_length+1 );
  478.         full_length = len_p(data);
  479.         len = dqdata(data, message, mess_length);
  480.         message[len] = '\0';
  481.  
  482.         free( pap_p->message );
  483.         pap_p->message = message;
  484.  
  485.         if (PPPtrace) {
  486.             trace_log(PPPiface,"%s PPP/PAP %s %s: %s",
  487.                 fsm_p->ppp_p->iface->name,
  488.                 (len < mess_length) ? "Short"
  489.                    : (mess_length < full_length) ? "Long"
  490.                     : "Valid",
  491.                 (hdr->code == CONFIG_ACK) ? "Ack" : "Nak",
  492.                 message);
  493.         }
  494.         return (len < mess_length  ||  mess_length < full_length);
  495.     }
  496.     free_p(data);
  497.     PPP_DEBUG_CHECKS( "PAP: missing message count" );
  498.     return -1;
  499. }
  500.  
  501.  
  502. /************************************************************************/
  503. /*            E V E N T   P R O C E S S I N G            */
  504. /************************************************************************/
  505.  
  506. /* Process incoming packet */
  507. void
  508. pap_proc(fsm_p,bp)
  509. struct fsm_s *fsm_p;
  510. struct mbuf *bp;
  511. {
  512.     struct pap_s *pap_p = fsm_p->pdv;
  513.     struct config_hdr hdr;
  514.  
  515.     PPPtrace = fsm_p->ppp_p->trace;
  516.     PPPiface = fsm_p->ppp_p->iface;
  517.  
  518.     if ( ntohcnf(&hdr, &bp) == -1 )
  519.         fsm_log( fsm_p, "short authentication packet" );
  520.  
  521.     if (PPPtrace > 1)
  522.         trace_log(PPPiface, "%s PPP/%s Recv,"
  523.             "  option: %s, id: %d, len: %d",
  524.             fsm_p->ppp_p->iface->name,
  525.             fsm_p->pdc->name,
  526.             fsmCodes[hdr.code],
  527.             hdr.id,    hdr.len);
  528.  
  529.     hdr.len -= CONFIG_HDR_LEN;        /* Length includes envelope */
  530.     trim_mbuf(&bp, hdr.len);        /* Trim off padding */
  531.  
  532.     switch(hdr.code) {
  533.     case CONFIG_REQ:
  534.         if ( pap_request(fsm_p, &hdr, bp) == 0) {
  535.             pap_opening(fsm_p, PPP_AP_LOCAL);
  536.         }
  537.         break;
  538.  
  539.     case CONFIG_ACK:
  540.         if (pap_check(fsm_p, &hdr, bp) == 0) {
  541.             alert ( pap_p->pp, -1 );
  542.             pap_opening(fsm_p, PPP_AP_REMOTE);
  543.         }
  544.         break;
  545.  
  546.     case CONFIG_NAK:
  547.         if (pap_check(fsm_p, &hdr, bp) == 0) {
  548.             stop_timer(&(fsm_p->timer));
  549.  
  550.             /* Must have sent a bad username or password */
  551.             free ( pap_p->username );
  552.             pap_p->username = NULLCHAR;
  553.             free ( pap_p->password );
  554.             pap_p->password = NULLCHAR;
  555.  
  556.             psignal ( pap_p, 1 );
  557.         }
  558.         break;
  559.  
  560.     default:
  561.         if (PPPtrace)
  562.             trace_log(PPPiface, "%s PPP/Pap Unknown packet type: %d;"
  563.                 " dropping packet",
  564.                 fsm_p->ppp_p->iface->name,
  565.                 hdr.code);
  566.         free_p(bp);
  567.         break;
  568.     }
  569. }
  570.  
  571.  
  572. /* Timeout while waiting for reply from remote host */
  573. static void
  574. pap_timeout(vp)
  575. void *vp;
  576. {
  577.     struct fsm_s *fsm_p = (struct fsm_s *)vp;
  578.     struct pap_s *pap_p = fsm_p->pdv;
  579.  
  580.     PPPtrace = fsm_p->ppp_p->trace;
  581.     PPPiface = fsm_p->ppp_p->iface;
  582.  
  583.     fsm_log( fsm_p, "Timeout" );
  584.  
  585.     if (fsm_p->retry > 0) {
  586.         free ( pap_p->message );
  587.         pap_p->message = strdup("Request timeout");
  588.         psignal ( pap_p, 1 );
  589.     } else {
  590.         free ( pap_p->message );
  591.         pap_p->message = strdup("Request retry exceeded");
  592.         psignal ( pap_p, 1 );
  593.         pwait ( NULL );
  594.         fsm_log(fsm_p, "Request retry exceeded");
  595.         pap_shutdown(fsm_p);
  596.     }
  597. }
  598.  
  599.  
  600. /************************************************************************/
  601. /*            I N I T I A L I Z A T I O N            */
  602. /************************************************************************/
  603.  
  604. void
  605. pap_down(fsm_p)
  606. struct fsm_s *fsm_p;
  607. {
  608.     struct pap_s *pap_p = fsm_p->pdv;
  609.  
  610.     if ( pap_p == NULL )
  611.         return;
  612.  
  613.     PPPtrace = fsm_p->ppp_p->trace;
  614.     PPPiface = fsm_p->ppp_p->iface;
  615.  
  616.     fsm_log(fsm_p, "Down");
  617.  
  618.     fsm_p->flags = FALSE;
  619.  
  620.     switch ( fsm_p->state ) {
  621.     case fsmREQ_Sent:
  622.         stop_timer(&(fsm_p->timer));
  623.         alert ( pap_p->pp, EABORT );
  624.         /* fallthru */
  625.     case fsmOPENED:
  626.     case fsmLISTEN:
  627.     case fsmTERM_Sent:
  628.         fsm_p->state = fsmCLOSED;
  629.         break;
  630.  
  631.     case fsmCLOSED:
  632.         /* Already closed; nothing to do */
  633.         break;
  634.     };
  635. }
  636.  
  637.  
  638. static void
  639. pap_free(fsm_p)
  640. struct fsm_s *fsm_p;
  641. {
  642.     struct pap_s *pap_p = fsm_p->pdv;
  643.  
  644.     free( pap_p->username );
  645.     free( pap_p->password );
  646.     free( pap_p->message );
  647. }
  648.  
  649.  
  650. /* Initialize configuration structure */
  651. void
  652. pap_init(ppp_p)
  653. struct ppp_s *ppp_p;
  654. {
  655.     struct fsm_s *fsm_p = &(ppp_p->fsm[Pap]);
  656.     struct timer *t;
  657.  
  658.     PPPtrace = ppp_p->trace;
  659.     PPPiface = ppp_p->iface;
  660.  
  661.     PPP_DEBUG_ROUTINES("pap_init()");
  662.  
  663.     if (fsm_p->pdv != NULL)
  664.         return;        /* already initialized */
  665.  
  666.     fsm_p->ppp_p = ppp_p;
  667.     fsm_p->pdc = &pap_constants;
  668.     fsm_p->pdv = callocw(1,sizeof(struct pap_s));
  669.  
  670.     fsm_p->try_req = fsm_p->pdc->try_req;
  671.     fsm_p->try_nak = fsm_p->pdc->try_nak;
  672.     fsm_p->try_terminate = fsm_p->pdc->try_terminate;
  673.  
  674.     fsm_p->state = fsmCLOSED;
  675.     fsm_p->retry = fsm_p->try_req;
  676.     fsm_p->retry_nak = fsm_p->try_nak;
  677.  
  678.     /* Initialize timer */
  679.     t = &(fsm_p->timer);
  680.     t->func = (void (*)())pap_timeout;
  681.     t->arg = (void *)fsm_p;
  682.     set_timer(t, fsm_p->pdc->timeout);
  683.     fsm_timer(fsm_p);
  684.     stop_timer(t);
  685. }
  686.  
  687.  
  688. /* Initialize state machine for local */
  689. int
  690. pap_local(ppp_p)
  691. struct ppp_s *ppp_p;
  692. {
  693.     struct fsm_s *fsm_p = &(ppp_p->fsm[Pap]);
  694.  
  695.     PPPtrace = ppp_p->trace;
  696.  
  697.     PPP_DEBUG_ROUTINES("pap_local()");
  698.  
  699.     fsm_p->state = fsmLISTEN;
  700.     fsm_p->flags |= PPP_AP_LOCAL;
  701.     ppp_p->flags |= PPP_AP_LOCAL;
  702.     fsm_p->retry = fsm_p->try_req;
  703.     return 0;
  704. }
  705.  
  706.  
  707. /* Initialize state machine for remote */
  708. int
  709. pap_remote(ppp_p)
  710. struct ppp_s *ppp_p;
  711. {
  712.     struct fsm_s *fsm_p = &(ppp_p->fsm[Pap]);
  713.     struct pap_s *pap_p = fsm_p->pdv;
  714.     char *ifn;
  715.  
  716.     PPPtrace = ppp_p->trace;
  717.  
  718.     PPP_DEBUG_ROUTINES("pap_remote()");
  719.  
  720.     fsm_p->state = fsmREQ_Sent;
  721.     fsm_p->flags |= PPP_AP_REMOTE;
  722.     ppp_p->flags |= PPP_AP_REMOTE;
  723.  
  724.     /* build a process/session to monitor user/password progress */
  725.     ifn = if_name( ppp_p->iface, " PAP" );
  726.     pap_p->pp = newproc( ifn,
  727.         512, pap_monitor, 0, ppp_p->iface, fsm_p, 0);
  728.     free( ifn );
  729.  
  730.     return 0;
  731. }
  732.  
  733.  
  734.